<?php
class OrderModel extends Model
{

    public $rules = array(
        'user_id' => array('required'),
        'product_id' => array('required'),
        'quantity' => array('required'),
        'required_date' => array('required'),
        'create_date' => array('required'),
    );
    public $attributes = array();
    public $tableName = '`order`';

    public function beforeSave()
    {
        $this->attributes['create_date'] = date('Y-m-d H:i:s');
    }

    public function getAllCities()
    {
        return $this->getAll("SELECT * FROM city");
    }

    public function getAllProducts()
    {
        return $this->getAll("SELECT * FROM product");
    }

    public function getOrdersByUserID($id)
    {
        return $this->getAll("SELECT * FROM {$this->tableName} JOIN product ON product.id = {$this->tableName}.product_id WHERE user_id=:user_id", array(':user_id' => $id));
    }
}